using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace QLThuChi.Repositories
{
	#region using
	using QLThuChi.Models;
	#endregion
	public class VLXDRepository
	{
		public static List<VLXD> SelectAll()
		{
			return DataContext.Instance.VLXDs.OrderBy(item => item.TenVLXD).ToList();
		}

		public static VLXD SelectByID(int mavlxd)
		{
			return DataContext.Instance.VLXDs.FirstOrDefault(item => item.MaVLXD == mavlxd );
		}

		public static bool Insert(VLXD obj)
		{
			try
			{
				DataContext.Instance.VLXDs.AddObject(obj);
				DataContext.Instance.SaveChanges();
				return true;
			}
			catch
			{
				return false;
			}
		}

		public static bool Delete(int mavlxd)
		{
			try
			{
				var delitem = DataContext.Instance.VLXDs.FirstOrDefault(item => item.MaVLXD == mavlxd );
				DataContext.Instance.VLXDs.DeleteObject(delitem);
				DataContext.Instance.SaveChanges();
				return true;
			}
			catch
			{
				return false;
			}
		}

		public static bool Save()
		{
			try
			{
				DataContext.Instance.SaveChanges();
				return true;
			}
			catch
			{
				return false;
			}
		}

		public static List<VLXD> RetrieveByID(int mavlxd)
		{
			return (from item in DataContext.Instance.VLXDs where  item.MaVLXD == mavlxd  select item).ToList();
		}

		public static List<VLXD> SelectByMaDonViTinh(int madonvitinh)
		{
			var lstItem = (from item in DataContext.Instance.VLXDs where item.MaDonViTinh == madonvitinh select item).ToList();
			return lstItem;
		}

	}
}